package studentproject.main.service;


import studentproject.main.dao.StudentDao;
import studentproject.main.domain.Student;

import java.util.ArrayList;

public class StudentService {
    private static StudentDao studentDao = new StudentDao();
    public int isExist(String id) {
        int index = -1;
        ArrayList<Student> list = studentDao.find();
        for (int i = 0; i < list.size(); i++) {
            Student student = list.get(i);
            if(id.equals(student.getId())){
                index = i;
                return index;
            }
        }
        return index;
    }

    public boolean add(Student student) {
        boolean flag = studentDao.add(student);
        return flag;
    }

    public boolean update(int index,Student student) {
        boolean flag = studentDao.update(index,student);
        return flag;
    }

    public boolean delete(int index) {
        boolean flag = studentDao.delete(index);
        return flag;
    }

    public boolean getList() {
        boolean flag = studentDao.getList();
        return flag;
    }

    public ArrayList<Student> find() {
        return studentDao.find();
    }
}
